package com.itcat.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itcat.api.mysql.OmsOrderReturnApplyApi;
import com.itcat.mapper.OmsOrderReturnApplyMapper;
import com.itcat.mysql.param.OmsOrderReturnApplyParam;
import com.itcat.mysql.pojo.OmsOrderReturnApply;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Arrays;
import java.util.List;

@DubboService
public class OmsOrderReturnApplyApiImpl implements OmsOrderReturnApplyApi {

    @Autowired
    private OmsOrderReturnApplyMapper omsOrderReturnApplyMapper;

    /**
     * 退货申请分页查询
     *
     * @param applyParam
     * @return
     */
    public Page<OmsOrderReturnApply> getPage(OmsOrderReturnApplyParam applyParam) {
        //创建分页对象
        Page<OmsOrderReturnApply> page = new Page<>(applyParam.getPageNum(), applyParam.getPageSize());
        //构建分页查询条件
        LambdaQueryWrapper<OmsOrderReturnApply> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(applyParam.getCreateTime() != null, OmsOrderReturnApply::getCreateTime, applyParam.getCreateTime());
        queryWrapper.like(applyParam.getHandleTime() != null, OmsOrderReturnApply::getHandleTime, applyParam.getHandleTime());
        queryWrapper.eq(applyParam.getStatus() != null, OmsOrderReturnApply::getStatus, applyParam.getStatus());
        queryWrapper.like(applyParam.getHandleMan() != null, OmsOrderReturnApply::getHandleMan, applyParam.getHandleMan());
        queryWrapper.like(applyParam.getId() != null, OmsOrderReturnApply::getId, applyParam.getId());
        //执行分页查询、
        Page<OmsOrderReturnApply> pageResult = omsOrderReturnApplyMapper.selectPage(page, queryWrapper);
        return pageResult;

    }

    /**
     * 批量删除退货申请
     *
     * @param ids
     */
    public void delete(Integer[] ids) {
        //将数组转化为集合
        List<Integer> list = Arrays.asList(ids);
        //调用omsOrderReturnApplyMapper执行批量删除
        omsOrderReturnApplyMapper.deleteBatchIds(list);

    }


    /**
     * 查看退货申请详情
     *
     * @param id
     * @return
     */
    public OmsOrderReturnApply findReturnApply(Integer id) {
        OmsOrderReturnApply omsOrderReturnApply = omsOrderReturnApplyMapper.selectById(id);
        return omsOrderReturnApply;
    }

    /**
     * 确认退货申请,收货
     *
     * @param omsOrderReturnApply
     */
    public void updateStatus(OmsOrderReturnApply omsOrderReturnApply) {
        omsOrderReturnApplyMapper.updateById(omsOrderReturnApply);

    }
}
